//
//  FoundCollectionViewCell.m
//  TourPlay
//
//  Created by dllo on 15/12/1.
//  Copyright © 2015年 王军岐. All rights reserved.
//

#import "FoundCollectionViewCell.h"

@interface FoundCollectionViewCell ()

@property (nonatomic, retain) UIImageView *imageV;
@property (nonatomic, retain) UIImageView *footerImageV;
@property (nonatomic, retain) UILabel *titleL;
@property (nonatomic, retain) UILabel *timeL;
@property (nonatomic, retain) UILabel *descriptionL;

@end

@implementation FoundCollectionViewCell
- (void)dealloc
{
    [_imageV release];
    [_footerImageV release];
    [_titleL release];
    [_timeL release];
    [_descriptionL release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews
{
 
    self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height * (3 / 5.f))];
//    // 设置照片左上角和右上角为圆角
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.imageV.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(3, 3)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.imageV.bounds;
    maskLayer.path = maskPath.CGPath;
    self.imageV.layer.mask = maskLayer;
    [maskLayer release];
    self.imageV.layer.masksToBounds = YES;
    // 缩放模式
    self.imageV.contentMode = UIViewContentModeScaleAspectFill;
    
    [self.contentView addSubview:self.imageV];
    [_imageV release];


    
    UIButton *playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    playBtn.backgroundColor = [UIColor clearColor];
    playBtn.frame = CGRectMake((self.imageV.frame.size.width - 80 * AUTOSCREEN_HEIGHT) / 2.f, (self.imageV.frame.size.height - 80 * AUTOSCREEN_HEIGHT) / 2.f, 80 * AUTOSCREEN_HEIGHT, 80 * AUTOSCREEN_HEIGHT);
    [playBtn setBackgroundImage:[UIImage imageNamed:@"iconfont-bofang.png"] forState:UIControlStateNormal];
    playBtn.layer.masksToBounds = YES;
    playBtn.layer.cornerRadius = playBtn.frame.size.height / 2.f;
    [playBtn addTarget:self action:@selector(playBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:playBtn];
    

    
    self.footerImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.imageV.frame.size.height - 2, self.contentView.frame.size.width, self.contentView.frame.size.height - self.imageV.frame.size.height + 2)];
    self.footerImageV.image = [UIImage imageNamed:@"wode_morenbg@2x.jpg"];
    UIBezierPath *maskPathFooterImageV = [UIBezierPath bezierPathWithRoundedRect:self.footerImageV.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(3, 3)];
    CAShapeLayer *maskLayerFooterImageV = [[CAShapeLayer alloc] init];
    maskLayerFooterImageV.frame = self.footerImageV.bounds;
    maskLayerFooterImageV.path = maskPathFooterImageV.CGPath;
    self.footerImageV.layer.mask = maskLayerFooterImageV;
    [maskLayerFooterImageV release];
    
    self.footerImageV.layer.masksToBounds = YES;
    self.footerImageV.image = [UIImage imageNamed:@"wode_morenbg@2x.jpg"];
    // 缩放模式
    self.footerImageV.contentMode = UIViewContentModeScaleAspectFill;
    self.footerImageV.image = [self.footerImageV.image boxblurImageWithBlur:0.99f];
    [self.contentView addSubview:self.footerImageV];
    [_footerImageV release];
    
    UIView *viewBlur = [[UIView alloc] initWithFrame:self.footerImageV.frame];
    viewBlur.backgroundColor = [UIColor blackColor];
    viewBlur.alpha = 0.5f;
    [self.contentView addSubview:viewBlur];
    [viewBlur release];
    
    UIView *blurView = [[UIView alloc] initWithFrame:self.footerImageV.frame];
    blurView.backgroundColor = [UIColor colorWithRed:0.18 green:0.16 blue:0.15 alpha:1];
    blurView.alpha = 0.5f;
    [self.contentView addSubview:blurView];
    [blurView release];
    

    
//    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
//    
//    UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:effect];
//    blurView.frame = self.footerImageV.frame;
//    [self.contentView addSubview:blurView];
//    [blurView release];
    
    
    self.titleL = [[UILabel alloc] initWithFrame:CGRectMake(10 *AUTOSCREEN_WIDTH, self.footerImageV.frame.origin.y + 5 * AUTOSCREEN_HEIGHT, self.footerImageV.frame.size.width - 20 * AUTOSCREEN_WIDTH, 40 * AUTOSCREEN_HEIGHT)];//Bradley Hand
//    self.titleL.backgroundColor = [UIColor orangeColor];
    self.titleL.font = [UIFont fontWithName:@"FZLTZCHJW--GB1-0" size:18.f];
    self.titleL.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.titleL];
    [_titleL release];
  
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(self.titleL.frame.origin.x, self.titleL.frame.size.height + self.titleL.frame.origin.y + 5 * AUTOSCREEN_HEIGHT, 150 * AUTOSCREEN_WIDTH, 2)];
    lineView.backgroundColor = [UIColor colorWithRed:0.43 green:0.44 blue:0.43 alpha:1];
    [self.contentView addSubview:lineView];
    [lineView release];
    
    
    self.timeL = [[UILabel alloc] initWithFrame:CGRectMake(self.titleL.frame.origin.x, lineView.frame.origin.y + lineView.frame.size.height + 5 * AUTOSCREEN_HEIGHT, lineView.frame.size.width, 30 * AUTOSCREEN_HEIGHT)];
//    self.timeL.backgroundColor = [UIColor orangeColor];
    self.timeL.textColor = [UIColor whiteColor];
    self.timeL.font = [UIFont fontWithName:@"Heiti TC" size:13.5f];
    [self.contentView addSubview:self.timeL];
    [_timeL release];

    self.descriptionL = [[UILabel alloc] initWithFrame:CGRectMake(self.timeL.frame.origin.x, self.timeL.frame.size.height + self.timeL.frame.origin.y + 5 * AUTOSCREEN_HEIGHT, self.titleL.frame.size.width, self.contentView.frame.size.height - (self.timeL.frame.size.height + self.timeL.frame.origin.y + 5 * AUTOSCREEN_HEIGHT) - 10 * AUTOSCREEN_HEIGHT)];
//    self.descriptionL.backgroundColor = [UIColor orangeColor];
    self.descriptionL.numberOfLines = 0;
    self.descriptionL.textColor = self.timeL.textColor;
    self.descriptionL.adjustsFontSizeToFitWidth = YES;
    self.descriptionL.font = [UIFont fontWithName:@"Heiti TC" size:13.f];
    [self.contentView addSubview:self.descriptionL];
    [_descriptionL release];
}
- (void)playBtnAction:(UIButton *)sender
{
    [self.delegate goToPlayer:sender];
}
- (void)setVideoMod:(VideoModel *)videoMod
{
    if (_videoMod != videoMod) {
        [_videoMod release];
        _videoMod = [videoMod retain];
    }
    NSURL *url = [NSURL URLWithString:self.videoMod.coverForDetail];
    [self.imageV sd_setImageWithURL:url placeholderImage:PICHOLDEER];
    
    self.titleL.text = self.videoMod.title;
    
    NSString *timeStr = [self TimeformatFromSeconds:self.videoMod.duration];
    self.timeL.text = [NSString stringWithFormat:@"#%@  /  %@", self.videoMod.category, timeStr];
    
    self.descriptionL.text = self.videoMod.descriptionStr;
    
}
-(NSString*)TimeformatFromSeconds:(NSInteger)seconds
{
    //format of hour
//    NSString *str_hour = [NSString stringWithFormat:@"%02ld",seconds/3600];
    //format of minute
    NSString *str_minute = [NSString stringWithFormat:@"%02ld",(seconds%3600)/60];
    //format of second
    NSString *str_second = [NSString stringWithFormat:@"%02ld",seconds%60];
    //format of time
    NSString *format_time = [NSString stringWithFormat:@"%@' %@''",str_minute,str_second];
    return format_time;
}

@end
